import java.util.*;

public class p2670{
  public static  int countmines(char[][] grid,int x,int y){
    int ans = 0;
        int rows = grid.length;
        int cols = grid[0].length;
        // 定义周围位置的偏移量，包括上、下、左、右、左上、右上、左下、右下
        int[] dx = {-1, -1, -1, 0, 0, 1, 1, 1};
        int[] dy = {-1, 0, 1, -1, 1, -1, 0, 1};
        for (int i = 0; i < 8; i++) {
            int newX = x + dx[i];
            int newY = y + dy[i];
            // 检查新位置是否在矩阵范围内，并且该位置是否是地雷 '*'
            if (newX >= 0 && newX < rows && newY >= 0 && newY < cols && grid[newX][newY] == '*') {
                ans++;
            }
        }
        return ans;
}
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int row = sc.nextInt();
    int col = sc.nextInt();

    char[][] matrix = new char[row][col];

    for (int i = 0; i < row; i++) {
            String line = sc.next();
            for (int j = 0; j < col; j++) {
                matrix[i][j] = line.charAt(j);
            }
        }

    for(int i = 0;i<row;i++){
      for(int j = 0;j<col;j++){
        if(matrix[i][j] == '*'){
          continue;
        }
        else{
          int count = countmines(matrix,i,j);
          matrix[i][j] = (char) (count + '0');
        }
        }
      }
  // 输出更新后的矩阵
        for (int i = 0; i < row; i++) {
            for (int j = 0; j < col; j++) {
                System.out.print(matrix[i][j]);
            }
            System.out.println();
        }
        sc.close();

    }
  }

